/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-12-12 下午1:55 Created by dwzhang
 */
package com.jade.bss.base.customer.impl;

import com.jade.bss.base.customer.EnterpriseDao;
import com.jade.bss.base.customer.CustomerException;
import com.jade.bss.base.customer.info.EnterpriseInfo;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.criterion.Restrictions;
import com.jade.framework.base.criterion.sql.SqlUtils;
import com.jade.framework.base.util.PagingList;

import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

/**
 * 采用JPA方式实现的地址数据访问接口。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-12-12 下午1:55
 */
@Named ("bss_enterpriseInfoDao")
public class JpaEnterpriseDao  implements EnterpriseDao
{
    private static final String SQL = "SELECT enterpriseInfo FROM com.jade.bss.base.customer.info.EnterpriseInfo enterpriseInfo";
    @PersistenceContext (unitName = "default")
    protected EntityManager entityManager;

    public void add(EnterpriseInfo address)
            throws CustomerException
    {
        entityManager.persist(address);
    }

    public void update(EnterpriseInfo address)
            throws CustomerException
    {
        entityManager.merge(address);
    }


    public void remove(EnterpriseInfo address)
            throws CustomerException
    {
        entityManager.remove(address);
    }

    public EnterpriseInfo get(long id)
    {
        return entityManager.find(EnterpriseInfo.class, id);
    }

    public PagingList<EnterpriseInfo> query(Criteria criteria)
    {
        return SqlUtils.sqlQuery(SQL, entityManager, criteria);
    }
}
